package cn.t.web.user;

import cn.t.converter.user.AssignRightsConverter;
import cn.t.core.controller.BaseController;
import cn.t.dto.user.ResourceInfoDTO;
import cn.t.dto.user.RoleAssignParticipantRequest;
import cn.t.dto.user.RoleAssignResourceRequest;
import cn.t.dto.user.RoleInfoDTO;
import cn.t.facade.user.RoleInfoFacade;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 角色信息表服务入口
 *
 * @author l
 */
@Slf4j
@RestController
@RequestMapping("roleInfo")

@AllArgsConstructor
public class RoleInfoController extends BaseController<RoleInfoDTO, RoleInfoFacade> {


    @PostMapping("/assignRights")
    public RoleInfoDTO assignRights(@Valid @RequestBody RoleAssignResourceRequest request) {
        RoleInfoDTO roleInfoDTO = assignRightsConverter.toRoleInfoDTO(request);
        List<ResourceInfoDTO> resourceInfoDtoList = assignRightsConverter.toResourceDtoList(request);
        facade.assignRights(roleInfoDTO, resourceInfoDtoList);
        return roleInfoDTO;
    }


    @PostMapping("/assignParticipants")
    public Boolean assignParticipants(@Valid @RequestBody RoleAssignParticipantRequest request) {


        return facade.assignParticipants(request.getRoleId(), request.getUserIds());

    }


    @PostMapping("save")
    @Override
    public Boolean save(@Valid @RequestBody RoleInfoDTO dto) {
        return facade.add(dto);
    }

    @Autowired
    private AssignRightsConverter assignRightsConverter;


}

